local remainNum = redis.call('hget', KEYS[1], KEYS[2])
local oldAmount = tonumber(redis.call('hget', KEYS[1], KEYS[3]))
local newAmount = tonumber(ARGV[1])
local remainAmount = tonumber(ARGV[2])

if oldAmount == newAmount then
    redis.call('hset', KEYS[1], KEYS[3], remainAmount)
    redis.call('hset', KEYS[1], KEYS[2], remainNum - 1)
else
    return 0
end

return 1;